using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
using Vin.Extension.Framework.Dto;
using Vin.Extension.Framework.Quartz.Entities;
using Vin.Tool.Core.JsonCategory.Converters;

namespace Vin.Extension.Framework.Quartz.Dto.Entities;

public record SysJobDto : VinFrameworkBaseEntityDto
{
    /// <summary>
    /// 任务名称
    /// </summary>
    [Required(ErrorMessage = "任务名称不能为空")]
    public string? Name { get; set; }

    /// <summary>
    /// 任务分组
    /// </summary>
    public long? GroupId { get; set; }

    /// <summary>
    /// 任务分组名称
    /// </summary>
    [Required(ErrorMessage = "任务分组不能为空")]
    public string? GroupName { get; set; }

    /// <summary>
    /// 任务执行类型
    /// </summary>
    [Required(ErrorMessage = "任务执行类型不能为空")]
    public JobExecuteType? ExecuteType { get; set; }

    /// <summary>
    /// 程序集路径
    /// </summary>
    public string? AssemblyPath { get; set; }

    /// <summary>
    /// 执行的程序集名称
    /// </summary>
    public string? AssemblyName { get; set; }

    /// <summary>
    /// 执行的任务类名
    /// </summary>
    [Required(ErrorMessage = "任务类名不能为空")]
    public string? ClassName { get; set; }

    /// <summary>
    /// 任务参数
    /// </summary>
    public List<JobParams> Parameters { get; set; } = new();

    /// <summary>
    /// 是否立即启动一次
    /// </summary>
    public bool? FirstExecute { get; set; }

    /// <summary>
    /// 开始时间
    /// </summary>
    [JsonConverter(typeof(LongTimeToStringConverter))]
    public long? StartTime { get; set; }

    /// <summary>
    /// 结束时间
    /// </summary>
    [JsonConverter(typeof(LongTimeToStringConverter))]
    public long? EndTime { get; set; }

    /// <summary>
    /// 任务触发器类型
    /// </summary>
    [Required(ErrorMessage = "任务触发器类型不能为空")]
    public JobTriggerType? TriggerType { get; set; }

    /// <summary>
    /// 循环类型
    /// </summary>
    public JobLoopType? LoopType { get; set; }

    /// <summary>
    /// 循环次数
    /// </summary>
    public int? LoopCount { get; set; }

    /// <summary>
    /// 间隔类型
    /// </summary>
    public JobIntervalType? IntervalType { get; set; }

    /// <summary>
    /// 间隔值
    /// </summary>
    public int? IntervalValue { get; set; }

    /// <summary>
    /// Cron表达式
    /// </summary>
    public string? Cron { get; set; }

    /// <summary>
    /// 任务状态
    /// </summary>
    [JsonConverter(typeof(EnumToStringConverter<JobStatus>))]
    public JobStatus? Status { get; set; }

    /// <summary>
    /// 已完成的循环次数
    /// </summary>
    public int? CompletedLoopCount { get; set; }

    /// <summary>
    /// 错误次数
    /// </summary>
    public int? ErrorCount { get; set; }

    /// <summary>
    /// 最后一次执行时间
    /// </summary>
    [JsonConverter(typeof(LongTimeToStringConverter))]
    public long? LastExecuteTime { get; set; }
}